﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Admin.Master" Inherits="System.Web.Mvc.ViewPage<VietPublisher.BSL.BK.T_BK_Book>" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    Create
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <script type="text/javascript">
        function PopupAuthor() {
            //step 1: get all value in Author
            var authorName = "";
            var Author = $("#AllAuthorList option");
            var numberAll = parseInt(Author.length);
            for (var i = 0; i < numberAll; i++) {
                authorName += "," + Author[i].getAttribute('value');
            }
            //step 2: pass value to popup author to modify
            Book_Script.popupAuthor(authorName);
        }

        function PopupPublisher() {
            Book_Script.popupPublisher();
        }
        function PopupCategory() {
            Book_Script.popupCategory();
        }

        //set to dropdownList
        function loadDivAuthor(Author) {
            // step 1: cat chuoi ra thanh 2 mang can thieta

            var data = Author.split(',');
            var length = data.length;
            var authorList = $("#cbxAuthor option");
            var finalList = $("#cbxAuthor");

            for (var i = 0; i < length; i++) {
                if (data[i].toString() == "") {
                    continue;
                }
                var authorId = (data[i].split('!'))[0]
                var authorName = (data[i].split('!'))[1]
                var duplicate = 0;
                for (var j = 0; j < authorList.length; j++) {
                    if (authorList[j].getAttribute("value") == authorId) {
                        duplicate = 1;
                    }
                }
                if (duplicate == 0) {

                    finalList.append('<option value=' + authorId + '>' + authorName + '</option>');
                }
            }
            //get all data about author set to hidden AuthorGroupID
            var result = "";
            var authorResult = $("#cbxAuthor option");
            for (var i = 0; i < authorResult.length; i++) {
                result += "," + authorResult[i].getAttribute("value");
            }

            $("#AuthorGroupID").val(result);

        }
        function loadDivPublisher(Publisher) {
            // step 1: cat chuoi ra thanh 2 mang can thieta

            var data = Publisher.split(',');
            var length = data.length;
            var PublisherList = $("#cbxPublisher option");
            PublisherList.remove();
            var finalList = $("#cbxPublisher");

            for (var i = 0; i < length; i++) {
                if (data[i].toString() == "") {
                    continue;
                }
                var PublisherId = (data[i].split('!'))[0]
                var PublisherName = (data[i].split('!'))[1]
                var duplicate = 0;
                for (var j = 0; j < PublisherList.length; j++) {
                    if (PublisherList[j].getAttribute("value") == PublisherId) {
                        duplicate = 1;
                    }
                }
                if (duplicate == 0) {

                    finalList.append('<option value=' + PublisherId + '>' + PublisherName + '</option>');
                }
            }

            //get all data about Publisher set to hidden PublisherID
            var result = "";
            var PublisherResult = $("#cbxPublisher option");
            for (var i = 0; i < PublisherResult.length; i++) {
                result += "," + PublisherResult[i].getAttribute("value");
            }

            $("#PublisherID").val(result);

        }
        function loadDivCategory(Category) {
            // step 1: cat chuoi ra thanh 2 mang can thieta

            var data = Category.split(',');
            var length = data.length;
            var CategoryList = $("#cbxCategory option");
            CategoryList.remove();
            var finalList = $("#cbxCategory");

            for (var i = 0; i < length; i++) {
                if (data[i].toString() == "") {
                    continue;
                }
                var CategoryId = (data[i].split('!'))[0]
                var CategoryName = (data[i].split('!'))[1]
                var duplicate = 0;
                for (var j = 0; j < CategoryList.length; j++) {
                    if (CategoryList[j].getAttribute("value") == CategoryId) {
                        duplicate = 1;
                    }
                }
                if (duplicate == 0) {

                    finalList.append('<option value=' + CategoryId + '>' + CategoryName + '</option>');
                }
            }

            //get all data about Category set to hidden CategoryID
            var result = "";
            var CategoryResult = $("#cbxCategory option");
            for (var i = 0; i < CategoryResult.length; i++) {
                result += "," + CategoryResult[i].getAttribute("value");
            }

            $("#CategoryID").val(result);
        }

        function loadDivImage(GroupIdImage) {

            $("#imageDiv").load("/Book/LoadImage?GroupIdImage=" + GroupIdImage);

        }
        function AddBook() {

            var valid = Book_Script.addbookValidate();
            if (valid) {
                alert("create");
                document.forms["BookForm"].submit();
            }
        }
       
    </script>
    
    <form id="BookForm" action="/Book/Create" method="post">
    <div class="Clearfix">
       <div id="imageDiv">
        <%Html.RenderPartial("_BookUploadImage", 0); %>
        </div>
        <div id="bookInfomationDiv" class="Clearfix">
            <%Html.RenderPartial("_bookInfomationDiv", Model); %>
        </div>
    </div>
    
    <div class="Clearfix">
        <div id="authorDiv">
            <%Html.RenderPartial("_AuthorDiv"); %>
        </div>
    
        <div id="publisherDiv">
            <%Html.RenderPartial("_publisherDiv"); %>
        </div>
        <div id="categoryDiv">
            <%Html.RenderPartial("_categoryDiv"); %>
        </div>
    </div>
    
    </form>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="Navigation" runat="server">
</asp:Content>
<asp:Content ID="Content4" ContentPlaceHolderID="MenuLeft" runat="server">
</asp:Content>
<asp:Content ID="Content5" ContentPlaceHolderID="Toolbar" runat="server">
     <input type="button" id="btnAddBook" value="Add Book" onclick="AddBook();" />
</asp:Content>
